<?php
use EasyWeChat\Factory;

class ModelSettingApp extends Model {
      
      public function load($key, $secret) {
            if (!empty($key) && !empty($secret)) {
                  $query = $this->db->query(sprintf("SELECT * FROM `%s` WHERE `app_key` = '%s' AND `app_secret` = '%s'",
                        "app",
                        $this->db->escape($key),
                        $this->db->escape($secret)
                  ));
                  return $query->row;
            }
            return null;
      }

      public function miniApp($config) {
            $config = [
                  'app_id' => $config['weixin_app_id'],
                  'secret' => $config['secret'],
                  'response_type' => $config['response_type'],
                  'log' => [
                      'level' => $config['log_level'],
                      'file' => DIR_LOGS.'wechat.log',
                  ],
            ];
            return Factory::miniProgram($config);
      }

}